<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 2015/3/4
 * Use : ...
 * File: AbstractFacade.php
 */
abstract class AbstractFacade
{
    static protected $key;

    static protected $instance = [];

    static public function getInstance()
    {
        $key = static::getKey();

        if (empty(static::$instance[$key]))
        {
            static::$instance[$key] = new $key;
        }

        return static::$instance[$key];
    }

    /**
     * __callStatic
     * @param string $name
     * @param array  $args
     * @return  mixed
     */
    public static function __callStatic($name, $args = array())
    {
        return call_user_func_array(array(static::getInstance(), $name), $args);
    }


    public static function reset()
    {
        static::$instance = [];
    }

    static public function getKey()
    {
        if (static::$key)
        {
            return get_called_class();
        }

        return static::$key;
    }

    static public function setKey($value)
    {
        static::$key = (string)$value;
    }



}